'use strict'

import './css/main.scss';
import React from 'react';
import ReactDOM from 'react-dom';
import { PageContainer } from './page/page.js';

function appLauch(){
    try {
        ReactDOM.render(
            <PageContainer platform="mobile" />,
            document.getElementById('root'),
            (d) => {
                console.log('app launch');
            }
        );
    
    } catch (e) {
        console.error(e)
    };

}

// const importMobile = function () {
//     import(/* webpackChunkName: "mobile" */ './mobile.js').then( ({ default: _ })  => {
//         // _();

//     }).catch(error => 'An error occurred while loading the component');
// }

const app = function () {
    let body = document.getElementsByTagName('body')[0];
    if (!body) {
        throw ('没有body元素');
    }
    let root = document.createElement('div');
    root.setAttribute('id', 'root');
    root.setAttribute('class', 'root');
    body.appendChild(root);
    let mask = document.createElement('div');
    mask.setAttribute('id','app-mask');
    body.appendChild(mask);
    if (window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) {
        document.documentElement.classList.add('MicroMessenger');
    }
    // if (!ReactDOM || !React) {
    //     throw ('React失效');
    // }
    appLauch();
}

export default app;